/*
 * =====================================================================================
 *
 *       Filename:  sqlist_1.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  04/25/2011 10:11:06 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *        Company:  
 *
 * =====================================================================================
 */

#include <stdio.h>
#include <string.h>
#include "SqList.h"

BINT32 init_list(sqlist *L)
{
    sqlist *list;
    list = L;
    list->elem = (elemtype *)malloc(LIST_INIT_SIZE * sizeof(sqlist));
    if (NULL == list->elem)
        return -1;
    list->length = 0;
    list->listsize = LIST_INIT_SIZE;

    return 0;
}

BINT32 destroy_list(sqlist *L)
{
    free(L->elem);
    L->elem = NULL;
    L->length = 0;
    L->listsize = 0;
    return 0;
}

BINT32 clear_list(sqlist *L)
{
    L->length = 0;
    L->listsize = LIST_INIT_SIZE;
    return 0;
}

BINT32 list_empty(sqlist *L)
{
    if (L->length == 0)
        return 0;
    return -1;
}

BINT32 list_lenth(sqlist *L)
{
    return L->length;
}

BINT32 get_elem(sqlist *L, int i, elemtype *e)
{
    if (L->length < i || i < 1)
        return -1;
    e = L->elem + (i-1);
    return 0;
}

BINT32 LocateElem(sqlist *L, elemtype e, COMPARE compare)
{
    if (L->length <= 0) 
        return -1;
    BINT32 i = L->length - 1;
    for (;i >= 0; i--) {
        if (!compare(e, (L->elem + i)))
            return i;
    }
    
    return -2;
}

BINT32 prior_elem(sqlist *L, elemtype cur_e, elemtype *pre_e)
{
    BINT32 i = 0
    for (; i >= 0; i--) 
    {
        if ( cur_e == *(L->elem + i))
        {
            if (i == 0)
                return -2;
            pre_e = (L-> elem + (i-1));
        }
        
    }
}









